/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_ADAPTER_STATE_MACHINE_H
#define SLE_ADAPTER_STATE_MACHINE_H

#include "sle_timer.h"
#include "sle_state_machine.h"

namespace OHOS {
namespace NearLink {
namespace SleStandard {
const std::string TURNING_ON_STATE = "TurningOn";
const std::string TURN_ON_STATE = "TurnOn";
const std::string TURNING_OFF_STATE = "TurningOff";
const std::string TURN_OFF_STATE = "TurnOff";

const int SLE_ENABLE_DISABLE_TIMEOUT_TIME = 5000;

enum SleAdapterStateMessage {
    MSG_ADAPTER_ENABLE_REQ,
    MSG_ADAPTER_ENABLE_CMP,
    MSG_ADAPTER_DISABLE_REQ,
    MSG_ADAPTER_DISABLE_CMP,
    MSG_ADAPTER_ENABLE_TIMEOUT,
    MSG_ADAPTER_DISABLE_TIMEOUT,
};

class SleAdapterStateMachine : public StateMachine {
public:
    SleAdapterStateMachine() = default;
    ~SleAdapterStateMachine() = default;
    SleErrorCode Initialize();
};

class TurningOn : public State {
public:
    TurningOn(SleAdapterStateMachine &stateMachine, const std::string &name);
    ~TurningOn() = default;

    bool Entry() override;
    void Exit() override;
    bool Dispatch(const Message &msg) override;

private:
    SleAdapterStateMachine &adapterStateMachine_;
    std::unique_ptr<Timer> adapterTimer_ = nullptr;
};

class TurnOn : public State {
public:
    TurnOn(SleAdapterStateMachine &stateMachine, const std::string &name)
        : State(name), adapterStateMachine_(stateMachine) {};
    ~TurnOn() = default;

    bool Entry() override;
    void Exit() override;
    bool Dispatch(const Message &msg) override;

private:
    SleAdapterStateMachine &adapterStateMachine_;
};

class TurningOff : public State {
public:
    TurningOff(SleAdapterStateMachine &stateMachine, const std::string &name);
    ~TurningOff() = default;

    bool Entry() override;
    void Exit() override;
    bool Dispatch(const Message &msg) override;

private:
    SleAdapterStateMachine &adapterStateMachine_;
    std::unique_ptr<Timer> adapterTimer_ = nullptr;
};

class TurnOff : public State {
public:
    TurnOff(SleAdapterStateMachine &stateMachine, const std::string &name)
        : State(name), adapterStateMachine_(stateMachine) {};
    ~TurnOff() = default;

    bool Entry() override;
    void Exit() override;
    bool Dispatch(const Message &msg) override;

private:
    SleAdapterStateMachine &adapterStateMachine_;
};
} // SleStandard
} // NearLink
} // OHOS
#endif // SLE_ADAPTER_STATE_MACHINE_H